<?php
namespace Home\Controller;
use Think\Controller;
class MobileController extends CommonController {
	
	

    public function goodsimage(){
        $goodsid = I('get.goodsid',0,'intval') ;
        if(!$goodsid) die;
			
        //商品信息
        $Archives = M("Goods");
        $where['goods_id'] = $goodsid;
		$where['goods_state'] = 1;
        $data = $Archives->where($where)->find();
 
		
		//商品相册
		$Images = M("GoodsImages");
        $img_where['goods_commonid'] = $data['goods_commonid'];
		$img_data = $Images->field('goods_image')->where($img_where)->limit(5)->select();
		
		//获取图片完整地址
		foreach($img_data as $k => $v){
			$type = explode("." , $v['goods_image']);
			$img_data[$k]['goods_image'] = 'data/upload/shop/store/goods/'.$data['store_id'].'/'.$type[0].'_240.'.$type[1];
		}
		
		$data['images'] = $img_data;
	
		//商品介绍
		$Desc = M("GoodsCommon");
        $desc_where['goods_commonid'] = $data['goods_commonid'];
		$desc_data = $Desc->field('mobile_body')->where($desc_where)->find();
		unset ($data['goods_image']);
		$text = array();
	    // var_dump($data['mobile_body']);
		if(!$desc_data['mobile_body']){
			$data['mobile_body'] = "";
		}else{
			$mobile_body = unserialize($desc_data['mobile_body']);
			foreach($mobile_body as $v) {
                if ($v['type'] == 'image') {
                    $text[]['image'] = $v['value'];
                }
                if ($v['type'] == 'text') {
                    $text[]['text'] = $v['value'];
                }
            }

			
		}
        
		$this->assign('data',$text);
		$this->display();
	}
	
	public function form(){
		$path = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/token/';
		$file= $path."123.png";
		
		$result = @unlink ($file); 
		$this->display();
	}
	
	 public function thumb(){
				$upload = new \Think\Upload();// 实例化上传类
				$upload->maxSize   =     3145728 ;// 设置附件上传大小
				$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
				$upload->rootPath  =     dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/data/upload/shop/avatar/'; // 设置附件上传根目录
				$upload->autoSub  =     false; // 设置附件上传（子）目录
				$upload->saveName = 'avatar__123';
				// 上传文件 
				echo $upload->saveName;
				$string = ($_FILES['photo']['name']);
				$array = explode('.',$string);
				$ext = end($array);
				die;
				$info   =   $upload->uploadOne($_FILES['photo']);
				if(!$info) {// 上传错误提示错误信息
					$this->error($upload->getError());
				}else{// 上传成功
					$this->success('上传成功！');
				}
 
 
	 }
	 
	 public function download(){
		 $this->display();
	 }


}